home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / mmailp.idb / usr / lib / Zmail / bin / showaudio.z / showaudio
Encoding:
Text File  |  1997-01-22  |  6.2 KB  |  213 lines

  1. #!/bin/csh -fb
  2. # (The "-fb" might need to be changed to "-f" on some systems)
  3. #
  4. # Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
  5. # Permission to use, copy, modify, and distribute this material 
  6. # for any purpose and without fee is hereby granted, provided 
  7. # that the above copyright notice and this permission notice 
  8. # appear in all copies, and that the name of Bellcore not be 
  9. # used in advertising or publicity pertaining to this 
  10. # material without the specific, prior written permission 
  11. # of an authorized representative of Bellcore.  BELLCORE 
  12. # MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY 
  13. # OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS", 
  14. # WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  15. #
  16.  
  17.  
  18. if (! $?METAMAIL_TMPDIR) then
  19.     set METAMAIL_TMPDIR=/tmp
  20. endif
  21.  
  22. # First, figure out which machine to play it on!
  23. set thishost=`hostname`
  24.  
  25. # Note that there are some special lines in here that only work at Bellcore,
  26. # Specifically involving phone playback from the machine "greenbush".
  27. # Everything should work fine at other sites, though
  28. set AUDIOBINDIR=/u/andrew/phone-sau/bin
  29. set AUDIOPHONEHOST=greenbush
  30. set AUDIOPHONEHOSTLONG=greenbush.bellcore.com
  31. set AUDIOLOGMAIL=andrew@thumper.bellcore.com
  32. set ORG="Bellcore"
  33. set STDINPUT=0
  34. if ("$1" == "-p") then
  35.     set AUDIOPHONE=$2
  36.     shift
  37.     shift
  38. endif
  39. if ("$1" == "-s") then
  40.     set AUDIOSPEAKERFORCE = 1
  41.     shift
  42. endif
  43. if ($?AUDIOPHONE || $?AUDIOPHONEFORCE) then
  44.     goto playphone
  45. endif
  46. if (! -d $AUDIOBINDIR) then
  47.     set AUDIOSPEAKERFORCE=1
  48. endif
  49.  
  50. if ("$1" == "-") then
  51.     set STDINPUT=1
  52.     shift
  53. endif
  54. if ($#argv < 1) then
  55.     set STDINPUT=1
  56. endif
  57.     
  58. if (! $STDINPUT && ! $?AUDIOSPEAKERFORCE && ! $?AUDIOPHONEFORCE) then
  59.     if ($?MM_NOTTTY) then
  60.     if ($MM_NOTTTY == 1) then
  61.         setenv MM_NOTTTY 0
  62.         xterm -e showaudio $*:q
  63.         exit 0
  64.     endif
  65.     endif
  66. choosehardware:
  67.     echo This program can display audio on the speakers of some workstations, 
  68.     echo "or (at some sites) it can call you on the telephone.  Please choose one:"
  69.     echo ""
  70.     echo "1 -- Use the computer's speaker"
  71.     echo "2 -- Call me on the telephone"
  72.     echo ""
  73.     echo -n "Which do you prefer (1 or 2)? "
  74.     set ans=$<
  75.     if ($ans == 2)  then
  76.     echo "OK, we'll use the telephone..."
  77.     set AUDIOPHONEFORCE=1
  78.     echo "In the future, you can avoid this question by setting the environment variable"
  79.     echo "AUDIOPHONEFORCE to 1"
  80.     goto playphone
  81.     else if ($ans == 1) then
  82.         echo "OK, Attempting to play the audio using your computer's speaker.."
  83.         set AUDIOSPEAKERFORCE=1
  84.     echo "In the future, you can avoid this question by setting the environment variable"
  85.     echo "AUDIOSPEAKERFORCE to 1"
  86.     else
  87.     echo "That is NOT one of your choices."
  88.     goto choosehardware
  89.     endif
  90. endif
  91.  
  92. set audiohost=$thishost
  93. if ($?DISPLAY) then
  94.     set audiohost=`echo $DISPLAY | sed -e 's/:.*//'`
  95.     if ($audiohost == "unix") set audiohost=$thishost
  96.     if ($audiohost == "") set audiohost=$thishost
  97. endif
  98. if ($?AUDIOHOST) then
  99.     set audiohost=$AUDIOHOST
  100. endif
  101.  
  102. if ($audiohost != $thishost) then
  103.     echo Sending audio to $audiohost...
  104.     if ($?MMS_AUDIO) then
  105.         if ($STDINPUT) then
  106.             cat | mms -host $audiohost "show audio/basic" -
  107.         else
  108.             cat $*:q | mms -host $audiohost "show audio/basic" -
  109.         endif
  110.         exit 0
  111.     endif
  112.  
  113. # The next two lines are very inefficient, but not everyone has their path right for an rsh
  114.     pushd ~ >& /dev/null
  115.     set thisprog=`which showaudio`
  116.     popd >& /dev/null
  117.     if ($STDINPUT) then
  118.         cat | rsh $audiohost $thisprog -s -
  119.     else
  120.         cat $*:q | rsh $audiohost $thisprog  -s -
  121.     endif
  122.     exit 0
  123. endif
  124.  
  125. if (-f /usr/sbin/sfplay) then
  126.     if ($#argv >= 1) then
  127.     exec /usr/sbin/sfplay -i mu-law chan 1 rate 8000 end $*:q
  128.     else
  129.     cat > ${METAMAIL_TMPDIR}/audio.$$
  130.     /usr/sbin/sfplay -i mu-law chan 1 rate 8000 end ${METAMAIL_TMPDIR}/audio.$$
  131.     rm ${METAMAIL_TMPDIR}/audio.$$
  132.     exit 0
  133.     endif
  134. else if (-d /usr/sony) then
  135.     set dev=/dev/sb0
  136. else if (-e /usr/bin/audioplay) then
  137. #  Solaris 2.0
  138.     /usr/bin/audioconvert -i raw,voice -f sun $*:q | /usr/bin/audioplay
  139.     exit $status
  140. else if (-e /bin/audioplay) then
  141. #  Solaris 2.0
  142.     /bin/audioconvert -i raw,voice -f sun $*:q | /bin/audioplay
  143.     exit $status
  144. else
  145.     set dev=/dev/audio
  146. endif
  147.  
  148. if (-w $dev) then
  149. echo Playing audio on $thishost using $dev, one moment please...
  150. if ($#argv >= 1) then
  151.         cat $*:q > $dev
  152. else
  153.         cat > $dev
  154. endif
  155. exit 0
  156. endif
  157.  
  158. playphone:
  159. if (-d $AUDIOBINDIR) then
  160.               set thisprog=`which showaudio`
  161.     if (! $?AUDIOPHONE) then
  162.         if ($?MM_NOTTTY) then
  163.         if ($MM_NOTTTY == 1) then
  164.             setenv MM_NOTTTY 0
  165.             xterm -e $thisprog $*:q
  166.             exit 0
  167.         endif
  168.         endif
  169.         echo This message contains audio, which can be sent to your telephone.
  170.         echo Please enter the telephone number at which you would like to hear this
  171.         echo -n "audio message as you would dial it from INSIDE ${ORG}:  "
  172.         set AUDIOPHONE=$<
  173.     endif
  174.     if ($thishost == $AUDIOPHONEHOST || $thishost == $AUDIOPHONEHOSTLONG) then
  175.         echo Calling Phone number $AUDIOPHONE
  176.         echo "You MUST SAY HELLO when you answer the phone, or you will not hear the message."
  177.         mail -s "showaudio: `whoami` called $AUDIOPHONE" $AUDIOLOGMAIL < /dev/null
  178.         if ($STDINPUT) then
  179.             cat $AUDIOBINDIR/../GREET.au $*:q - | $AUDIOBINDIR/play -\# $AUDIOPHONE -
  180.         else
  181.             cat $AUDIOBINDIR/../GREET.au $*:q | $AUDIOBINDIR/play -\# $AUDIOPHONE -
  182.         endif
  183.         echo All done
  184.         exit 0
  185.     else
  186.         echo Trying to rsh to $AUDIOPHONEHOST to send audio via telephone
  187.         cat $*:q | rsh $AUDIOPHONEHOST $thisprog -p $AUDIOPHONE -
  188.         exit 0
  189.     endif
  190. endif
  191. echo ""
  192. echo This message contains an audio mesage, which can not currently be
  193. echo played on this type of workstation.   If you log into an appropriate 
  194. echo "machine (currently a SPARCstations or Sony News workstation)"
  195. echo and read this message there, you should be able to hear the audio
  196. echo message.  
  197. echo ""
  198. if (! $?MM_NOTTTY) set MM_NOTTTY=0
  199. if ($MM_NOTTTY == 1) then
  200.     set fname=/tmp/mm.aud.$$
  201. else
  202.     echo -n "Do you want to write the audio out to a file [y] ? "
  203.     set ANS=$<
  204.     if ("$ANS" =~ n* ||  "$ANS" =~ N* ) exit 0
  205.     echo -n "File name:"
  206.     set fname=$<
  207. endif
  208. cp $1 $fname
  209. if ($status == 0) echo Wrote raw audio file: $fname
  210. exit 0
  211.  
  212.